<template>
  <div class="pass">
    <!-- 通行证管理 -->
    <el-breadcrumb separator="/">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>编辑住户信息</el-breadcrumb-item>
    </el-breadcrumb>
  </div>

  <el-card>
    <div class="height">
      <el-form :label-position="labelPosition" label-width="80px">
        <el-form-item label="姓名">
          <el-input v-model="formInline.uname"></el-input>
        </el-form-item>

        <el-form-item label="身份证号">
          <el-input v-model="formInline.idCard"></el-input>
        </el-form-item>

        <el-form-item label="年龄">
          <el-input v-model="formInline.age"></el-input>
        </el-form-item>

        <el-form-item label="性别">
          <el-select v-model="formInline.gender" placeholder="请选择">
            <el-option label="男" value="男"></el-option>
            <el-option label="女" value="女"></el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="地址">
          <el-input
            v-model="formInline.address"
            placeholder="修改地址"
          ></el-input>
        </el-form-item>

        <el-form-item label="电话号码">
          <el-input
            v-model="formInline.phone"
            placeholder="修改电话号码"
          ></el-input>
        </el-form-item>

        <el-form-item label="备注">
          <el-input v-model="formInline.note"></el-input>
        </el-form-item>
        <div class="button">
          <el-form-item>
            <el-button color="red" @click="submitForm">保存</el-button>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="back">返回</el-button>
          </el-form-item>
        </div>
      </el-form>
    </div>
  </el-card>
</template>

    <script>
import { updateBaseApi} from "../api/index1.js";
import { ElMessage } from "element-plus";
export default {
  data() {
    return {
      labelPosition: "left",
      formInline: {
        id:"",
        address: "",
        age: "",
        gender: "",
        idCard: "",
        note: "",
        phone: "",
        uname: "",
        ustatus:""
      },
    //   ruleForm: {
    //     user: "",
    //     region: "",

    //     desc: "",
    //   },
    //   rules: {
    //     desc: [{ required: true, message: "请填写活动形式", trigger: "blur" }],
    //   },
    };
  },
    mounted(){
        //隐式传递： this.$route.params.参数名！！拿到跳转过来时传递的参数 页面刷新后  不保存！！
    console.log(this.$route.params)
    this.formInline = this.$route.params
  },
  methods: {
    back() {
      this.$router.push({
        path: "../views/userManage", //要跳转的页面的路由
      });
    },
    //查询
    onSubmit() {
      console.log("submit!");
    },
    submitForm() {
      updateBaseApi(this.formInline).then((res) => {
        console.log(res);
        this.formInline = {};
                // 2.提示用户添加成功
            
        if (res.code == 20000) {
          ElMessage({
            message: "更新成功",
            type: "success",
          });
        }
        this.$router.push({
          path: "../views/userManage", //要跳转的页面的路由
        });
      });
    },
    //提交校验
    // submitForm(formName) {
    //     this.$refs[formName].validate((valid) => {
    //         if (valid) {
    //             alert('submit!');
    //         } else {
    //             console.log('error submit!!');
    //             return false;
    //         }
    //     });
    // },
    // resetForm(formName) {
    //     this.$refs[formName].resetFields();
    // }
  },
};
</script>

    <style lang="less" scoped>
.el-form {
  width: 800px;
}

.notice {
  margin-top: 10px;
  font-weight: bold;
}

.height {
  margin-top: 20px;
}
.height {
  line-height: 10px;
}
.el-input {
  width: 220px;
}
.el-card {
  margin-top: 10px;
}
.button {
  display: flex;
}
</style>
